#!/usr/bin/python
#Auther : MillionLee

'''
Do dummypost by cron V2

do dummypost for everyone in the userlist same as "do dummypost"
but with today's updates check. Date check been removed.(new feature in V2)
'''

import datetime
import pytz

from getDummyText import getDummyText
from doOAuthUpdate import OAuthUpdate
from userListMorau import getUserList
from userListCoushin import updateUser
from getUserTimelines import GetUserTimeline

getter = GetUserTimeline()
poster = OAuthUpdate()
print 'Content-Type: text/plain'

for (key, (secret, name, lastUpdateDateStr)) in getUserList().items():
    try:
        getter.setToken(key, secret)
        dateStrNow = datetime.datetime.now(pytz.timezone("PRC")).strftime("%m%d%y")
        if dateStrNow == getter.getUserLastOriginalUpdateTime():
        #conti just when had been updated today.
        #the last update is either Before or after today, do post.
            continue
        #do post
        poster.setToken(key, secret)
        poster.update(getDummyText())
        #refresh the update time
        updateUser(key, lastUpdateDateStr = dateStrNow)
    except Exception, e:
        #print except, user name and his key
        print e, name, key
        continue